#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/27
# @Author  : LiJun
# @Email   : lijun@tianyancha.com
# @Version : 1.0.0

# 运行时不生成__pycache__
import random

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium_0627.po_page.base_page import BasePage
import allure


class AddMemberPage(BasePage):

    # 编辑添加成员信息
    def edit_member(self, name, uuid, phone):
        from selenium_0627.po_page.contact_page import ContactPage

        with allure.step("添加姓名"):
            self.find_send(*self.by_maps(self.element["ADD_CONTACT_NAME"]), message=name)
        with allure.step("添加账号"):
            self.find_send(*self.by_maps(self.element["ADD_CONTACT_UID"]), message=uuid)
        with allure.step("随机性别"):
            by, locate = self.by_maps(self.element["ADD_CONTACT_SEX"])
            self.find_click(by, locate.format(random.randint(1, 2)))
        with allure.step("下滑页面"):
            self.driver.execute_script(self.element["JS_DOWN_PAGE"])

        with allure.step("输入手机号"):
            self.find_send(*self.by_maps(self.element["ADD_CONTACT_PHONE"]), message=phone)
        with allure.step("点击保存"):
            self.find_click(*self.by_maps(self.element["ADD_CONTACT_SAVE"]))

        return ContactPage(self.driver, self.element)
